package com.vegetable.modules.service.outbound;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.vegetable.common.annotation.SalesDataPermission;
import com.vegetable.common.utils.R;
import com.vegetable.modules.entity.finance.po.ReconciliationPO;
import com.vegetable.modules.entity.finance.vo.FinancialCollectionDetailVO;
import com.vegetable.modules.entity.outbound.SalesOut;
import com.vegetable.modules.entity.outbound.excel.SalesOutDetailExport;
import com.vegetable.modules.entity.outbound.excel.SalesOutImport;
import com.vegetable.modules.entity.outbound.po.SalesOutQueryPO;
import com.vegetable.modules.entity.outbound.po.SalesOutStatisticsPO;
import com.vegetable.modules.entity.outbound.po.UpdateHedgingStatePO;
import com.vegetable.modules.entity.outbound.po.UpdateOrderTimePO;
import com.vegetable.modules.entity.outbound.vo.SalesOutPageVO;

import java.util.List;

/**
 * <p>
 * 销售出库单 服务类
 * </p>
 *
 * @author wangruijie
 * @since 2024-04-01
 */
public interface ISalesOutService extends IService<SalesOut> {

    /**
     * 销售出库列表查询
     *
     * @param po 查询参数
     * @return IPage<SalesOut> 分页数据
     */
    IPage<SalesOut> queryPage(SalesOutQueryPO po);

    /**
     * 综合统计销售出库单信息（不分页）
     * 统计金额、数量、重量、利润以及按费用类型分组的其他费用
     *
     * @param po 查询参数
     * @return SalesOutPageVO 统计结果（仅包含统计字段，不含分页数据）
     */
    SalesOutPageVO queryStatistics(SalesOutQueryPO po);

    /**
     * 详情销售出库
     * @param id null
     * @return R
     * @author wrj
     * @since 2024/3/7 下午4:35
     */
    R detailSalesOut(Long id);

    R detailsSalesOut(Long id);

    /**
     * 新增销售出库
     * @param otherDelivery null
     * @return R
     * @author wrj
     * @since 2024/3/7 下午4:35
     */
    R saveSalesOut(SalesOut otherDelivery) throws Exception;

    /**
     * 提交销售出库
     * @param otherDelivery null
     * @return R
     * @author wrj
     * @since 2024/3/7 下午4:35
     */
    R submitSalesOut(SalesOut otherDelivery) throws Exception;

    /**
     * 删除销售出库
     * @param id null
     * @return R
     * @author wrj
     * @since 2024/3/7 下午4:35
     */
    R deleteSalesOut(Long id) throws Exception;

    /**
     * 查询（未对账金额 > 0）可收款的销售订单
     * @param customerId null
     * @return R
     * @author wrj
     * @since 2024/4/15 上午9:31
     */
    List<SalesOut> canCollectionList(Long customerId);

    /**
     * 查询客商的可对账数据
     * @param po
     * @return List<FinancialCollectionDetailVO>
     * @author wrj
     * @since 2024/4/28 下午2:06
     */
    List<FinancialCollectionDetailVO> reconciliationList(ReconciliationPO po);

    /**
     * 查询未完成回款的销售出库单
     * @param customerId 客户ID
     * @return 未完成回款的销售出库单列表
     */
    List<FinancialCollectionDetailVO> uncompletedCollectionList(Long customerId);

    /**
     * 批量导入销售出库
     * @param orderList null
     * @return R
     * @author wrj
     * @since 2024/6/6 上午9:57
     */
    R uploadSalesOut(List<SalesOutImport> orderList) throws Exception ;

    R currentSalesOut(SalesOut otherDelivery) throws Exception;

    /**
     * 根据销售订单ID查询销售出库单
     * @param orderId
     * @return
     */
    SalesOut selectByOrderId(Long orderId);

    /**
     * 初始化包装单价
     */
    void initUnitPackCost();

    /**
     * 销售概况统计
     * @param po
     * @return
     */
    @SalesDataPermission(type = SalesDataPermission.PermissionType.CUSTOMER, filterParam = SalesOutStatisticsPO.class)
    R sequenceToGeneral(SalesOutStatisticsPO po);


    R salesOutStatisticsVO (SalesOutStatisticsPO po);
    SalesOut selectByOrderNo(String orderNo);

    /**
     * 一键出库
     * @param salesOrderId
     * @return
     * @throws Exception
     */
    R oneClickOut(Long salesOrderId) throws Exception;

    /**
     * 根据销售订单id校验
     * @param orderId
     */
    void checkOrderCostByOrderId(Long orderId);

    void checkOrderCostByStockId(Long stockId);

    List<SalesOutDetailExport> exportStatisticsSalesOut(SalesOutStatisticsPO po);

    R sequenceToDetail(SalesOutStatisticsPO po);

    /**
     * 更新销售出库单对冲状态
     * @param po 更新对冲状态参数对象
     * @return R
     * @author Qoder
     * @since 2025/10/21
     */
    R updateHedgingState(UpdateHedgingStatePO po);

    /**
     * 更新销售出库单和销售订单的订单时间
     * @param po 更新订单时间参数对象
     * @return R
     * @author Qoder
     * @since 2025/10/31
     */
    R updateOrderTime(UpdateOrderTimePO po);
}
